require("../css/index.less")

tool.footer("index")


window.onload = function () {
  // 渲染真实数据
  let rankingNumber = document.querySelector(".rankingNumber")
  let clockInDays = document.querySelector(".clockInDays")
  let clockInBtn = document.querySelector(".clockInBtn")
  let badgeSumNum = document.querySelector(".badgeSumNum")
  let userId = localStorage.getItem("userId")
  // 渲染首页数据函数
  function getInfo() {
    // 请求获取首页数据
    http.ajax({
      type: "get",
      url: '/headPageInfo',
      data: {
        userId: userId
      },
      success: function (res) {
        if (res.status === 0) {
          rankingNumber.textContent = res.data.rank
          clockInDays.textContent = res.data.punchIn
          badgeSumNum.textContent = res.data.insigniaNum
          if (res.data.isPunch === "true") {
            clockInBtn.textContent = "已打卡"
          } else {
            clockInBtn.textContent = "今日打卡"
          }
        }
      }
    })
  }
  // 进入页面获取数据 渲染页面
  getInfo()
  // 点击打卡
  clockInBtn.addEventListener("click", function () {
    // 请求获取打卡信息
    http.get("/clockIn", {
      userId: userId
    }, function (res) {
      if (res.status === 0) {
        tool.toast(1, "打卡成功")
        clockInBtn.textContent = "已打卡"
        // 打卡成功数据重新渲染
        getInfo()
      } else {
        tool.toast(0, res.msg)
        clockInBtn.textContent = "已打卡"
      }
    })
  })

  // 轮播图
  var mySwiper = new Swiper('.swiper', {
    direction: 'horizontal', // 水平horizontal或者垂直vertical切换选项
    loop: true, // 循环模式选项
    autoplay: true, //自动播放

    // 如果需要分页器
    pagination: {
      el: '.swiper-pagination',
    },

    // 如果需要前进后退按钮
    // navigation: {
    //   nextEl: '.swiper-button-next',
    //   prevEl: '.swiper-button-prev',
    // },

    // // 如果需要滚动条
    // scrollbar: {
    //   el: '.swiper-scrollbar',
    // },
  })








}